import request from '@/utils/request'
import type {
  ResApi,
  LoginRes,
  LoginType,
  UserListType,
  UserRes,
  addUserType,
  AssignRoleType,
} from '@/types/user'

// 封装登录接口
export const loginApi = (data: LoginType) => {
  return request<ResApi<LoginRes>>({
    method: 'post',
    url: '/user/login',
    data,
  })
}

// 获取用户列表
export const getUserListApi = (params: UserListType) => {
  return request<ResApi<UserRes[]>>({
    method: 'get',
    url: '/user/index',
    params,
  })
}

// 新增用户
export const addUserApi = (data: addUserType) => {
  return request<ResApi<null>>({
    method: 'post',
    url: '/user/create',
    data,
  })
}

// 删除用户
export const delUserApi = (params: UserRes) => {
  return request<ResApi<null>>({
    method: 'delete', //相当于get 参数是拼接到url的后面的
    url: '/user/delete',
    params,
  })
}

// 更新用户
export const updateUserApi = (data: UserRes) => {
  return request<ResApi<null>>({
    method: 'put', //相当于get 参数是拼接到url的后面的
    url: '/user/update',
    data,
  })
}

// 用户分配角色
export const assignUserRoleApi = (data: AssignRoleType) => {
  return request({
    method: 'put',
    url: '/user/assign',
    data,
  })
}
